package com.tian.service.impl;

import com.tian.convert.StationConvertUtil;
import com.tian.dto.StationInfoDto;
import com.tian.dto.StationQueryRespDto;
import com.tian.entity.Station;
import com.tian.mapper.StationMapper;
import com.tian.service.StationService;
import com.tian.util.CommonResult;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author tianwc  公众号：java后端技术全栈、面试专栏
 * @version 1.0.0
 * @date 2023年05月11日 21:18
 * 博客地址：<a href="http://woaijava.cc/">博客地址</a>
 */
@Service
public class StationServiceImpl implements StationService {

    @Resource
    private StationMapper stationMapper;

    @Override
    public CommonResult<StationQueryRespDto> selectListByStation(StationInfoDto stationInfoDto) {
        int count = stationMapper.selectListByStationCount(stationInfoDto);
        if (count == 0) {
            return CommonResult.success(new StationQueryRespDto());
        }
        List<Station> stationList = stationMapper.selectListByStation(stationInfoDto);
        StationQueryRespDto stationQueryRespDto = new StationQueryRespDto();
        stationQueryRespDto.setList(StationConvertUtil.convert(stationList));
        stationQueryRespDto.setCount(count);
        stationQueryRespDto.setStart(stationInfoDto.getStart() + stationList.size());
        return CommonResult.success(stationQueryRespDto);
    }
}
